package xuecheng.tool.core.log;

import org.springframework.util.StringUtils;

import ch.qos.logback.classic.filter.LevelFilter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.spi.FilterReply;
import lombok.Getter;
import lombok.Setter;

/**
 * 日志文件自定义过滤器
 *
 * @author PengXueCheng
 * @version 1.0.0
 **/
public class LogFileCustomFilter extends LevelFilter {

    /**
     * logger 名称
     */
    @Getter
    @Setter
    private String name;

    @Override
    public FilterReply decide(ILoggingEvent event) {
        if (!isStarted()) {
            return FilterReply.NEUTRAL;
        }

        if (event.getLoggerName().equals(name)) {
            return super.decide(event);
        } else {
            return onMismatch;
        }
    }

    @Override
    public void start() {
        if (!StringUtils.isEmpty(this.name)) {
            super.start();
        }
    }

}
